<?php 
include_once 'CarrinhoControl.php';

$productsCart = CarrinhoControl::getProductsCart($_SESSION['UsuarioIdUser']);

if(count($productsCart) > 0){
	
	echo "<tr class=\"row\" id=\"table-categories\">";
	echo "<th class=\"categories\">Quant</th>";
	echo "<th class=\"categories\">Foto</th>";
	echo "<th class=\"categories\">Descrição</th>";
	echo "<th class=\"categories\">Excluir</th>";
	echo "<th class=\"categories\">Preço Unitário</th>";
	echo "<th class=\"categories\">Total</th>";
	echo "</tr>";
	
	foreach ($productsCart as $product)
	{	
		
		if($product->Fotos[0] != null){
		$file = "imagensBanco/photo".$product->Id."". $product->Fotos[0][1];
		if(file_exists($file)) @unlink($file);
		$fp = fopen($file, "a");
		$escreve = fwrite($fp, $product->Fotos[0][0]);
		
		// Fecha o arquivo
		fclose($fp);
		}
			else
				$file = "imagensBanco/imagemIndisponivel.bmp";
		$categorias = implode(', ', $product->Categoria);
		
		
		echo "<tr class=\"row\">";
		echo "<td class=\"table-column amount\">".$product->Quantidade."</td>";
		echo "<td class=\"table-column column-photo\"><img class=\"photo\" src=\"".$file."\"/></td>";
		echo "<td class=\"table-column description\">";
		echo "<span class=\"product-name\">".$product->Nome."</span>";
		echo "<span class=\"product-status\">(".$product->Tipo.")</span>";
		echo "<span class=\"product-categories\">$categorias</span>";
		echo "</td>";
		echo "<td class=\"table-column delete\"><a class=\"link-delete\" href=\"acaoRemoverProdutoCarrinho.php?idProduct=".$product->Id."\">Excluir</a></td>";
		echo "<td class=\"table-column single-price\">".$product->UltimoPreco."</td>";
		$total = $product->UltimoPreco * $product->Quantidade;
		echo "<td class=\"table-column total-price\">".$total."</td>";
		echo "</tr>";
	}
	
	echo "</table>";
	
	echo "<div class=\"content\">";
	echo "<form action=\"acaoSolicitarOrcamentodoCarrinho.php\" method=\"POST\">";
	echo "<input class=\"submit\" type=\"submit\" value=\"Solicitar Orçamento\">";
	echo "</form>";
	echo "</div>";
}
else 
{
	echo "<br/>";
	echo "<br/>";
	echo "<br/>";
	echo "<span id=\"empty-car\">Não existem produtos adicionados ao carrinho.</span>";
	echo "</table>";
	echo "<div class=\"content\">";
	echo "</form>";
	echo "</div>";
}
?>